﻿<Base:WorkflowInstanceListBase xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
             xmlns:utils="clr-namespace:Rio.Framework.Pages.AppCode.Helpers.Utils"
             xmlns:conv="clr-namespace:Rio.Framework.Pages.Helpers.Converter"
             xmlns:workflow="clr-namespace:Rio.Framework.Pages.Workflow"
             xmlns:filterControls="clr-namespace:Rio.Framework.Pages.Workflow.Filters;assembly=Rio.Framework.Pages"
             x:Name="userControl"
             xmlns:Base="clr-namespace:Rio.Framework.Pages.Workflow.BaseClass"
             x:Class="Rio.Framework.Pages.Workflow.WorkflowInstanceTreeList"
             xmlns:converter="clr-namespace:Rio.Framework.Pages.AppCode.Helpers.Converter"
             xmlns:Localization="clr-namespace:Rio.Framework.Localisation;assembly=Rio.Framework.Localisation"
             Loaded="UserControlLoaded"
             mc:Ignorable="d"
             d:DesignHeight="768"
             d:DesignWidth="1024">

    <Base:WorkflowInstanceListBase.Resources>
        <conv:BoxMessageReadedToImageConverter x:Key="BoxMessageReadedToImageConverter" />
        <utils:WorkflowInstanceGridViewStyleSelector x:Key="WorkflowGridViewReadStyleSelector" />

        <DataTemplate x:Key="HistoryDetailsTemplate">
            <telerik:RadTabControl BackgroundVisibility="Collapsed"
                                   x:Name="RadTabHistory"
                                   Margin="8"
                                   VerticalAlignment="Center"
                                   Background="White">
                <telerik:RadTabItem Header="Historique du flux"
                                    x:Name="HistoricalTabHeader"
                                    DataContext="{Binding}"
                                    Margin="8,0,0,0"
                                    Height="24">
                    <telerik:RadGridView x:Name="HistoryGridView"
                                         AutoGenerateColumns="False"
                                         IsFilteringAllowed="True"
                                         CanUserReorderColumns="False"
                                         CanUserFreezeColumns="False"
                                         CanUserResizeColumns="False"
                                         ShowGroupPanel="False"
                                         SelectionMode="Single"
                                         SelectedItem="{x:Null}"
                                         Margin="6"
                                         Foreground="Black"
                                         HorizontalGridLinesBrush="{x:Null}"
                                         VerticalGridLinesBrush="{x:Null}"
                                         BorderBrush="{x:Null}"
                                         CanUserDeleteRows="False"
                                         CanUserInsertRows="False"
                                         CanUserSelect="False"
                                         GridLinesVisibility="None"
                                         RowIndicatorVisibility="Collapsed"
                                         Loaded="HistoryGridViewLoaded">
                        <telerik:RadGridView.Columns>
                            <telerik:GridViewDataColumn Header="Date"
                                                        IsReadOnly="True"
                                                        DataMemberBinding="{Binding DateAction}" />
                            <telerik:GridViewDataColumn Header="Action"
                                                        IsReadOnly="True"
                                                        DataMemberBinding="{Binding ActionLabel}"
                                                        DataFormatString="{}{0} par" />
                            <telerik:GridViewDataColumn Header="Utilisateur"
                                                        IsReadOnly="True"
                                                        DataMemberBinding="{Binding HistoUserFullName}" />
                            <telerik:GridViewDataColumn Header="Document"
                                                        IsReadOnly="True"
                                                        DataMemberBinding="{Binding DocumentName}" />
                            <workflow:WorkflowCommentColumn Header="Commentaire"
                                                            IsReadOnly="True"
                                                            DataMemberBinding="{Binding Comment}" />
                        </telerik:RadGridView.Columns>
                    </telerik:RadGridView>
                </telerik:RadTabItem>
            </telerik:RadTabControl>
        </DataTemplate>
        <converter:WorkflowStateToColorConverter x:Key="WorkflowStateToColorConverter" />
    </Base:WorkflowInstanceListBase.Resources>

    <Grid x:Name="LayoutRoot">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <telerik:RadToolBar Height="35">
            <telerik:RadMenuItem x:Name="buttonDisplay"
                                 Command="{Binding FlowActionPerfomedCommand, ElementName=userControl, Mode=TwoWay}"
                                 CommandParameter="display">
                <telerik:RadMenuItem.Header>
                    <StackPanel Orientation="Horizontal">
                        <Image Source="/Rio.Framework.Pages;component/Assets/Images/display.png"
                               Margin="0,0,5,0" />
                        <TextBlock x:Name="buttonDisplayHeader"
                                   Text="{Localization:Resx ResxKey=Display}"
                                   VerticalAlignment="Center" />
                    </StackPanel>
                </telerik:RadMenuItem.Header>
            </telerik:RadMenuItem>
            <telerik:RadMenuItem x:Name="buttonDelete"
                                 Command="{Binding FlowActionPerfomedCommand, ElementName=userControl, Mode=TwoWay}"
                                 CommandParameter="delete">
                <telerik:RadMenuItem.Header>
                    <StackPanel Orientation="Horizontal">
                        <Image Source="/Rio.Framework.Pages;component/Assets/Images/Delete.png"
                               Margin="0,0,5,0" />
                        <TextBlock x:Name="buttonDeleteHeader"
                                   Text="{Localization:Resx ResxKey=Delete}"
                                   VerticalAlignment="Center" />
                    </StackPanel>
                </telerik:RadMenuItem.Header>
            </telerik:RadMenuItem>
            <telerik:RadMenuItem x:Name="buttonRefresh"
                                 Command="{Binding FlowActionPerfomedCommand, ElementName=userControl, Mode=TwoWay}"
                                 CommandParameter="refresh">
                <telerik:RadMenuItem.Header>
                    <StackPanel Orientation="Horizontal">
                        <Image Source="/Rio.Framework.Pages;component/Assets/Images/refresh.png"
                               Margin="0,0,5,0" />
                        <TextBlock x:Name="buttonRefreshHeader"
                                   Text="{Localization:Resx ResxKey=Refresh}"
                                   VerticalAlignment="Center" />
                    </StackPanel>
                </telerik:RadMenuItem.Header>
            </telerik:RadMenuItem>

            <telerik:RadMenuItem x:Name="buttonRemind"
                                 Command="{Binding FlowActionPerfomedCommand, ElementName=userControl, Mode=TwoWay}"
                                 CommandParameter="remind">
                <telerik:RadMenuItem.Header>
                    <StackPanel Orientation="Horizontal">
                        <Image Source="/Rio.Framework.Pages;component/Assets/Images/Remind.png"
                               Margin="0,0,5,0" />
                        <TextBlock x:Name="buttonRemindHeader"
                                   Text="Relancer"
                                   VerticalAlignment="Center" />
                    </StackPanel>
                </telerik:RadMenuItem.Header>
            </telerik:RadMenuItem>
        </telerik:RadToolBar>

        <telerik:RadTreeListView x:Name="GridViewWorkflowMessages"
                             VerticalAlignment="Stretch"
                             HorizontalAlignment="Stretch"
                             SelectionMode="Extended"
                             AutoGenerateColumns="False"
                             CanUserDeleteRows="False"
                             CanUserInsertRows="False"
                             CanUserSelect="True" 
                                 
                             telerik:RadDragAndDropManager.AllowDrag="False"
                             IsFilteringAllowed="True"
                             ShowGroupPanel="True"
                             RowIndicatorVisibility="Collapsed"
                             SelectionChanged="GridViewWorkflowMessagesSelectionChanged"
                             RowStyleSelector="{StaticResource WorkflowGridViewReadStyleSelector}"
                             RowDetailsTemplate="{StaticResource HistoryDetailsTemplate}"
                             RowLoaded="WorkflowDefinitionsGridView_RowLoaded"    
                             RowIsExpandedChanged="WorkflowDefinitionsGridView_RowIsExpandedChanged"                                     
                             d:LayoutOverrides="Height"
                             Grid.Row="1"
                             ItemsSource="{Binding WorkflowInstances, ElementName=userControl}">
            <telerik:RadTreeListView.ChildTableDefinitions>
                <telerik:TreeListViewTableDefinition ItemsSource="{Binding Childs}" />
            </telerik:RadTreeListView.ChildTableDefinitions>
            <telerik:RadTreeListView.Columns>
                <telerik:GridViewToggleRowDetailsColumn UniqueName="ShowHistorical" />
                <telerik:GridViewSelectColumn />
                <!--<telerik:GridViewDataColumn UniqueName="GridViewWorkflowMessages_State"
                                            Header=""
                                            IsReadOnly="True"
                                            MinWidth="40"
                                            MaxWidth="40"
                                            DataMemberBinding="{Binding IsRead}">
                    <telerik:GridViewDataColumn.CellTemplate>
                        <DataTemplate>
                            <Image Source="{Binding IsRead, ConverterParameter=workflow, Converter={StaticResource BoxMessageReadedToImageConverter}}"
                                   HorizontalAlignment="Center"
                                   VerticalAlignment="Center"
                                   Width="20"
                                   Height="20" />
                        </DataTemplate>
                    </telerik:GridViewDataColumn.CellTemplate>
                    <telerik:GridViewDataColumn.FilteringControl>
                        <filterControls:ReadOrNotControl x:Name="ReadFilterControl" />
                    </telerik:GridViewDataColumn.FilteringControl>
                </telerik:GridViewDataColumn>-->
                <telerik:GridViewDataColumn UniqueName="GridViewWorkflowMessages_StateLabel"
                                            Header=""
                                            IsReadOnly="True"
                                            DataMemberBinding="{Binding StateLabel, Mode=TwoWay}">
                    <telerik:GridViewDataColumn.FilteringControl>
                        <workflow:WorkflowStateCustomFilter  x:Name="WorkflowStateCustomFilter" />
                    </telerik:GridViewDataColumn.FilteringControl>
                </telerik:GridViewDataColumn>

                <telerik:GridViewDataColumn UniqueName="GridViewWorkflowMessages_Sender"
                                            Header=""
                                            IsReadOnly="True"
                                            DataMemberBinding="{Binding SendedBy, Mode=TwoWay}"/>
                <telerik:GridViewDataColumn UniqueName="GridViewWorkflowMessages_Date"
                                            Header=""
                                            IsReadOnly="True"
                                            DataMemberBinding="{Binding CreatedOn, Mode=TwoWay}"/>
                <telerik:GridViewDataColumn UniqueName="GridViewWorkflowMessages_FlowName"
                                            Header=""
                                            IsReadOnly="True"
                                            DataMemberBinding="{Binding DefinitionName, Mode=TwoWay}"/>
                <telerik:GridViewDataColumn UniqueName="GridViewWorkflowMessages_Event"
                                            Header=""
                                            IsReadOnly="True"
                                            DataMemberBinding="{Binding StartingConditionLabel, Mode=TwoWay}"/>
                <telerik:GridViewDataColumn UniqueName="GridViewWorkflowMessages_SendTo"
                                            Header=""
                                            IsReadOnly="True"
                                            DataMemberBinding="{Binding Receivers, Mode=TwoWay}"/>
                <telerik:GridViewDataColumn UniqueName="GridViewWorkflowMessages_Receivers"
                                            Header=""
                                            IsReadOnly="True"
                                            DataMemberBinding="{Binding GroupName, Mode=TwoWay}"/>                

            </telerik:RadTreeListView.Columns>

            <telerik:RadContextMenu.ContextMenu>
                <telerik:RadContextMenu>
                    <telerik:RadMenuItem x:Name="DisplayMessageContextMenuWkf"
                                         Header="Afficher"
                                         Click="DisplayMessageContextMenuWkfClick">
                        <telerik:RadMenuItem.Icon>
                            <Image Source="/Rio.Framework.Pages;component/Assets/Images/display.png"
                                   Height="16"
                                   Width="16"
                                   Stretch="UniformToFill" />
                        </telerik:RadMenuItem.Icon>
                    </telerik:RadMenuItem>

                    <telerik:RadMenuItem IsSeparator="True" />

                    <telerik:RadMenuItem x:Name="DeleteContextMenuWkf"
                                         Header="Supprimer"
                                         Click="DeleteContextMenuWkfClick">
                        <telerik:RadMenuItem.Icon>
                            <Image Source="/Rio.Framework.Pages;component/Assets/Images/Delete.png"
                                   Stretch="UniformToFill" />
                        </telerik:RadMenuItem.Icon>
                    </telerik:RadMenuItem>
                </telerik:RadContextMenu>
            </telerik:RadContextMenu.ContextMenu>
        </telerik:RadTreeListView>
        <telerik:RadDataPager x:Name="DataPagerBoxWorkflow"
                              DisplayMode="FirstLastPreviousNextNumeric"
                              IsTotalItemCountFixed="False"
                              PageSize="100"
                              NumericButtonCount="10"
                              Source="{Binding WorkflowInstances, ElementName=userControl, Mode=TwoWay}"
                              Height="Auto"
                              VerticalAlignment="Bottom"
                              Grid.Row="2" />
    </Grid>
</Base:WorkflowInstanceListBase>
